package com.project.isaacwiki.mapper;

import com.project.isaacwiki.pojo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MapperItemOpera {

    @Insert("insert into items(id, name, quality, type, power, effect, create_time, create_id, change_time, change_id) " +
            "values(#{id}, #{name}, #{quality}, #{type}, #{power}, #{effect}, #{createTime}, #{createId}, #{changeTime}, #{changeId})")
    Integer createItem(Item item);

    @Insert("insert into items_attributes(id, max_hp, hp, damage, tears, `range`, shot_speed, speed, lucky, devil_probability, angel_probability) " +
            "values(#{id}, #{maxHp}, #{hp}, #{damage}, #{tears}, #{range}, #{shotSpeed}, #{speed}, #{lucky}, #{devilProbability}, #{angelProbability})")
    Integer createItemAttributes(ItemsAttributes itemsAttributes);

    Integer createSynergies(List<Synergy> synergies);

    Integer createItemPool(@Param("id") Integer id, @Param("itemPoolTypes") List<ItemPoolType> itemPoolTypes);

    @Insert("insert into item_img_path(item_id, path) values(#{itemId}, #{path})")
    Integer createItemImgPath(ItemImgPath itemImgPath);

    @Delete("delete from item_img_path where item_id = #{id}")
    Integer deleteItemImgPathById(Integer id);

    @Delete("delete from item_pool where item_id = #{id} ")
    Integer deleteItemPoolById(Integer id);

    @Delete("delete from items_attributes where id = #{id}")
    Integer deleteItemAttributesById(Integer id);

    @Delete("delete from synergy where item_a_id = #{id}")
    Integer deleteSynergyById(Integer id);

    @Delete("delete from items where id = #{id}")
    Integer deleteItemsById(Integer id);

    @Update("update item_img_path set path = #{path} where item_id = #{itemId}")
    Integer updateItemImgPath(ItemImgPath itemImgPath);

    @Update("update items set name = #{name}, quality = #{quality}, type = #{type}, power = #{power}, " +
            "effect = #{effect}, change_time = #{changeTime}, change_id = #{changeId} where id = #{id}")
    Integer updateItems(Item item);

    @Update("update items_attributes set max_hp = #{maxHp}, hp = #{hp}, damage = #{damage}, tears = #{tears}, `range` = #{range} , shot_speed = #{shotSpeed}, " +
            "speed = #{speed}, lucky = #{lucky}, devil_probability =#{devilProbability}, angel_probability = #{angelProbability} where id = #{id} ")
    Integer updateItemAttributes(ItemsAttributes itemsAttributes);

}
